import request from '@/utils/request'
import { User } from '../types/user'

/**
 * 分页获取用户列表
 * @param params 
 * @returns 
 */
export function userPaging(params: object) {
    return request({
      url: 'user/paging',
      method: 'get',
      params
    })
  }

  /**
   * 发送心跳检测
   */
  export function trackPresenceApi(data:object) {
    return request({
      url: 'auths/track-presence',
      method: 'post',
      data
    })
  }

  /**
   * 获取登录用户详细信息
   */
  export function getUserInfoApi() {
    return request({
      url: 'user/info',
      method: 'get'
    })
  }

  /**
   * 用户充值
   */
  export function userRechargeApi(amount:number) {
    return request({
      url: 'user/recharge?fee='+amount,
      method: 'post'
    })
  }

  /**
   * 修改用户密码
   */
  export function updateUserPasswordApi(data:object) {
    return request({
      url: 'user',
      method: 'put',
      data
    })
  }

  /**
   * 获取用户余额
   */
  export function getUserBalanceApi() {
    return request({
      url: 'user/balance',
      method: 'get'
    })
  }

  // 用户后台相关接口
export const userMangerApi = {
  // 分页列表
  list: (params: { pageNum: number; pageSize: number; status?: number }) =>
   request.get('/user/paging', { params }),

  // 新增
  add: (data: User) => request.post('/user', data),
  // 修改
  update: (data: User) => request.put('/user/update', data),
  // 批量删除
  deleteBatch: (params: { ids?: number[]}) => 
  request.delete(`/user`, {
    params: {
      ids: params.ids?.join(',')
    }
  }),
  // 单个删除
  delete:  (id: number) => request.delete(`/user/${id}`),
  // 导出excel
  exportExcel: () => request.get('/user/export', {  responseType: 'blob' }),
  // 下载模板
  downloadTemplate: () => request.get('/user/template', {  responseType: 'blob' }),
}
